<?php

namespace app\common\model;

use think\Db;
use think\Model;

class CommentModel extends Model
{
  protected $table = 'basic_comment';

  //获取评论列表
	public function getCommentByArticeId($param){
    $curPage = isset($param['page'])&&$param['page']>=1  ? $param['page']: 1;
    $pageSize = 12;
    $where = [
    	'c.status' => ['neq', 111],
    	'c.article_id' => $param['article_id']
    ];

    $totalRow = Db::table($this->table)->alias("c")->where($where)->count();
    $data = Db::field("c.*,u.nickname,u.figureurl")->table($this->table)
    ->alias("c")
    ->join("basic_user u","c.uid = u.id")
    ->where($where)
    ->order("id desc")
    ->page($curPage, $pageSize)
    ->select();

    foreach ($data as $key => $vo) {
    	$data[$key]['create_time'] = date("Y-m-d H:i:s",$vo['create_time']);
    }

    return [
        'page_size' => $pageSize,
        'total' => $totalRow,
        'curPage' => $curPage,
        'list' => $data
    ];
	}


	//评论
	public function comment($param){
		$data = [
			'uid' => $param['uid'],
			'article_id' => $param['article_id'],
			'comment' => $param['comment'],
			'create_time' => time(),
			'update_time' => time(),
		];
		return Db::table($this->table)->insert($data);
	}
}